<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
  <script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
  <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
  <script src="../layuimini/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
  <style>
    body {
      background-color: #ffffff;
    }
  </style>
</head>
<body>
<div class="layui-form layuimini-form">

  <div class="layui-form-item" id="area-picker">
    <div class="layui-form-item" style="width: 30%">
      <label class="layui-form-label">编号</label>
      <div class="layui-input-block">
        <input type="text" name="tId" value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item" style="width: 30%">
      <label class="layui-form-label">会员等级</label>
      <div class="layui-input-block">
          <input type="text" name="tLevel" value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item" style="width: 30%">
      <label class="layui-form-label">则扣率</label>
      <div class="layui-input-block">
        <input type="text" name="tDeduction" value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item" style="width: 30%">
      <label class="layui-form-label">详细描述</label>
      <div class="layui-input-block">
        <input type="text" name="tDescribe" value="" class="layui-input">
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-input-block">
        <button id="log-btn" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
      </div>
    </div>
</div>
</div>
<script>
  layui.use(['layer' , 'form' , 'layarea' , 'laydate'], function () {
    var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            layarea = layui.layarea,
            $ = layui.$;

    //地区选择控件
    layarea.render({
      elem: '#area-picker',
    });

    //监听提交
    form.on('submit(saveBtn)', function (data) {

      //这里需要转为JSON格式
      var da = JSON.stringify(data.field);

      $("#log-btn").attr("disabled","disabled").addClass("layui-btn-disabled");

      $.ajax({
        //注意：这里需要添加/
        url:"/member/addMember",
        method: "post",
        data: da,
        contentType: "application/json;charset=UTF-8",   // 注意：这里需要设置请求头，因为springmvc中默认接收的请求头为这个
        dataType: "json",
        success: function (res){
          if(res.code == 0){
            layer.msg("添加成功",{ icon: 6,time: 2000,anim: 5},function (){
              //刷新表格数据
              parent.refreshTable();
              //关闭窗口
              var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
              parent.layer.close(index); //再执行关闭
            });
          }else{
            $("#log-btn").removeAttr("disabled","disabled").removeClass("layui-btn-disabled");
            layer.msg(res.msg,{ icon: 2,time: 1000,anim: 6});
          }
        }
      })
      // // 关闭弹出层
      // layer.close(index);

      return false;
    });

  });
</script>
</body>
</html>